<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Process extends Admin_Controller {
	public function admincp_index(){
		admin_check_permission($this->module_id,'r',true);
		
		$schedule_list = $this->model->fetch('*',SCHEDULE_TABLE,"is_active = 1 AND route_way_id = 1",'start_time','asc',-1,0,true);
		$driver_list = $this->model->fetch('*',DRIVER_TABLE,'is_active = 1','name','asc',-1,0,true);
		$vehicle_list = $this->model->fetch('*',VEHICLE_TABLE,'is_active = 1','number_plate','asc',-1,0,true);
			
		$data = array (
			'start' => $this->input->post('start'),
			'per_page' => $this->input->post('per_page'),
			'module_name'=>$this->module_name,
			'module' => $this->module,
			'list_view_order_name' => '',
			'list_view_order_direction' =>'',
			'search_field' => '',
			'list_view_pagination' =>'',
			'search_filter'	=>	'',
			'list_page'=>'',
			
			'schedule_list' => $schedule_list,
			'driver_list' => $driver_list,
			'vehicle_list' => $vehicle_list
		);
	
		$this->session->set_userdata('start', $this->input->post('start'));
		$this->template->write_view('content','BACKEND/index',$data);
		$this->template->render();	
	}
	
	/*public function ajax_load_xeplich_content(){
		if(!empty($_POST)){
			$data = array();
			$selected_date = trim($this->input->post('selected_date'));
			$schedule_id = (int)$this->input->post('schedule_id');
			// $selected_date_int = strtotime($selected_date);
			$selected_date_int = $selected_date;
			$date_start_int  = mktime(0, 0, 0, date("m",$selected_date_int), date("d",$selected_date_int), date("Y",$selected_date_int));
			$date_end_int = mktime(23, 59, 59, date("m",$selected_date_int), date("d",$selected_date_int), date("Y",$selected_date_int));
			$date_start = date(DATETIME_FORMAT_DB,$date_start_int);
			$date_end = date(DATETIME_FORMAT_DB,$date_end_int);
			$book_condition = "is_active = 1 AND departure_date >= '{$date_start}' AND departure_date <= '{$date_end}' AND schedule_id = {$schedule_id}";
			
			$book_list = $this->model->fetch('*',BOOK_TABLE,$book_condition,'created','asc',-1,0,true);
			$data['book_list'] = $book_list;
			
			$driver_list = $this->model->fetch('*',DRIVER_TABLE,'is_active = 1','name','asc',-1,0,true);
			$data['driver_list'] = $driver_list;
			
			$vehicle_list = $this->model->fetch('*',VEHICLE_TABLE,'is_active = 1','number_plate','asc',-1,0,true);
			$data['vehicle_list'] = $vehicle_list;
			
			$this->load->view('BACKEND/ajax_load_xeplich_content',$data);
		}
	}*/
	
	public function ajax_book_list(){
		if(!empty($_POST)){
			$data = array();
			$selected_date = trim($this->input->post('selected_date'));
			$schedule_id = (int)$this->input->post('schedule_id');
			// $selected_date_int = strtotime($selected_date);
			$selected_date_int = $selected_date;
			$date_start_int  = mktime(0, 0, 0, date("m",$selected_date_int), date("d",$selected_date_int), date("Y",$selected_date_int));
			$date_end_int = mktime(23, 59, 59, date("m",$selected_date_int), date("d",$selected_date_int), date("Y",$selected_date_int));
			$date_start = date(DATETIME_FORMAT_DB,$date_start_int);
			$date_end = date(DATETIME_FORMAT_DB,$date_end_int);
			$book_condition = "is_active = 1 AND departure_date >= '{$date_start}' AND departure_date <= '{$date_end}' AND schedule_id = {$schedule_id}";
			
			$book_list = $this->model->fetch('*',BOOK_TABLE,$book_condition,'created','asc',-1,0,true);
			$data['book_list'] = $book_list;
			
			$this->load->view('BACKEND/ajax_book_list',$data);
		}
	}
	
	public function ajax_seat_list(){
		if(!empty($_POST)){
			$data = array();
			/*$driver_id = (int)$this->input->post('driver_id');
			$vehicle_id = (int)$this->input->post('vehicle_id');
			$seat_condition = "is_active = 1 AND vehicle_id = {$vehicle_id}";
			
			$seat_list = $this->model->fetch('*',SEAT_TABLE,$seat_condition,'created','asc',-1,0,true);
			$data['seat_list'] = $seat_list;*/
			
			$this->load->view('BACKEND/ajax_seat_list',$data);
		}
	}
}